package cn.lixin.hrm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@EnableWebSecurity
public class HrmAuthenConfig extends WebSecurityConfigurerAdapter {

    @Bean
    public PasswordEncoder getEncoder(){
        return new BCryptPasswordEncoder();
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers(HttpMethod.POST,"/login","/loginUser/login").permitAll()
                .antMatchers("/tenantType/list","/loginUser/entering").permitAll()
                .anyRequest().authenticated()
                .and().formLogin()
                .successForwardUrl("/loginUser/success")
                .and().logout().permitAll()
                .and().csrf().disable();
    }
    @Bean
    protected AuthenticationManager authenticationManager() throws Exception {
        return  super.authenticationManager();
    }
}